home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include <gl.h>
- #include <math.h>
- #include <stdio.h>
- #include "defines.h"
- #include "device.h"
- #include "nurb.h"
- #include "snurb.h"
- #include "draw.h"
-
- /* viewing */
- extern Matrix view_matrix;
-
- /* motion */
- extern Boolean moving_control, moving_object, zipping;
- extern Coord motion_origin[3];
-
- extern struct node_struct *root;
- extern struct node_struct *selected_patch;
- extern int move_s, move_t;
- extern int dest_s, dest_t;
- extern struct node_struct *zip_dest;
-
- extern float pixel_tolerance;
- extern long snurb_window;
-
- void draw_display(void)
- {
- clear_window();
- setnurbsproperty(N_PIXEL_TOLERANCE, pixel_tolerance);
-
- set_view(MVIEWING);
- multmatrix(view_matrix);
-
- /* depthcue(TRUE);
- lRGBrange(50,0,0,255,0,0,0,0x7fffff);
- draw_cube(); */
-
- draw_children(root->child,FALSE);
-
- #ifdef spaceball
- sbPrmpt();
- #endif
-
- swapbuffers();
- }
-
-
- /*
- * Draws all the children of the parent node. If the parent is selected, then
- * all of its children are also selected, and their control points and hulls
- * are drawn.
- */
- void draw_children(struct node_struct *child, Boolean parent_selected)
- {
- Boolean child_selected;
-
- if (child != NULL)
- {
- child_selected = (parent_selected || child->selected);
-
- if (child->node_type == PATCH)
- {
- if(child_selected)
- {
- depthcue(TRUE);
-
- /* note the stupidity check for when window system misses mouse
- up events */
- if ((moving_control || moving_object) && (child == selected_patch))
- {
- draw_control_points(child->patch->control, move_s, move_t);
-
- draw_drop_lines(child->patch->control[move_s][move_t]);
- }
- else if ( zipping && (child == zip_dest))
- draw_control_points(child->patch->control, dest_s, dest_t);
- else
- draw_control_points(child->patch->control, NONE, NONE);
-
- draw_hulls(child->patch->control);
- }
- else if ( zipping && (child == zip_dest))
- {
- depthcue(TRUE);
- draw_control_points(child->patch->control, dest_s, dest_t);
- draw_hulls(child->patch->control);
- }
-
-
- depthcue(FALSE);
- lmbind(MATERIAL, 1);
- draw_patch(child->patch->control);
- }
-
- draw_children(child->child, child_selected);
- draw_children(child->sibling, parent_selected);
- }
- }
-
-
-
- /*
- * Clears the window and reinitialized the control point markers to
- * none.
- */
- void clear_window(void)
- {
- cpack(0);
- clear();
- zclear();
- }
-
-
- void draw_control_points(Mesh control, int select_s, int select_t)
- {
- int s,t;
- int counter = 0;
-
- for(s = 0; s< NUMPOINTS; s++)
- for(t = 0; t < NUMPOINTS; t++)
- {
- if ((s == select_s) && (t == select_t))
- lRGBrange(50,50,50,255,255,255,0,0x7fffff);
- else
- lRGBrange(0,50,0,0,255,0,0,0x7fffff);
-
- pushmatrix();
- translate(control[s][t][0],
- control[s][t][1],
- control[s][t][2]);
- scale(.02, .02, .02);
-
- draw_cube();
- popmatrix();
- }
- }
-
-
- void draw_hulls(Mesh control)
- {
- int s, t;
-
- lRGBrange(0,50,0,0,255,0,0,0x7fffff);
-
- for(s = 0; s< NUMPOINTS; s++)
- for(t = 0; t < NUMPOINTS-1; t++)
- {
- bgnline();
- v3f(control[s][t]);
- v3f(control[s][t+1]);
- endline();
-
- bgnline();
- v3f(control[t][s]);
- v3f(control[t+1][s]);
- endline();
- }
- }
-
-
-
- void draw_drop_lines(Coord c[3])
- {
- Coord a[3],b[3];
- int i;
- extern Coord spaced_limit[3][2];
-
- lRGBrange(50,50,50,255,255,255,0,0x7fffff);
-
- for (i=0; i<3; i++)
- {
- a[0] = b[0] = c[0];
- a[1] = b[1] = c[1];
- a[2] = b[2] = c[2];
-
- a[i] = spaced_limit[i][0];
- b[i] = spaced_limit[i][1];
-
- bgnline();
- v3f(a);
- v3f(b);
- endline();
- }
-
-
- }
-
-
- /* The vertices of a cube centered about the origin with width 2 */
- Coord cube_vertex[8][3] =
- {
- {-1.0, -1.0, -1.0},
- {-1.0, -1.0, 1.0},
- {-1.0, 1.0, 1.0},
- {-1.0, 1.0, -1.0},
- { 1.0, -1.0, -1.0},
- { 1.0, -1.0, 1.0},
- { 1.0, 1.0, 1.0},
- { 1.0, 1.0, -1.0}
- };
-
-
- /*
- * Draws the cube with vertices defined above.
- */
- void draw_cube(void)
- {
- bgnclosedline();
- v3f(cube_vertex[0]);
- v3f(cube_vertex[1]);
- v3f(cube_vertex[2]);
- v3f(cube_vertex[3]);
- endclosedline();
-
- bgnclosedline();
- v3f(cube_vertex[4]);
- v3f(cube_vertex[5]);
- v3f(cube_vertex[6]);
- v3f(cube_vertex[7]);
- endclosedline();
-
- bgnline();
- v3f(cube_vertex[0]);
- v3f(cube_vertex[4]);
- endline();
-
- bgnline();
- v3f(cube_vertex[1]);
- v3f(cube_vertex[5]);
- endline();
-
- bgnline();
- v3f(cube_vertex[2]);
- v3f(cube_vertex[6]);
- endline();
-
- bgnline();
- v3f(cube_vertex[3]);
- v3f(cube_vertex[7]);
- endline();
- }
-
-
-
-
-
-
-
-